//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.ruoyi.web.controller.exam;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.live.exam.service.LiveExamTaskService;
import com.ruoyi.live.base.domain.LiveExamTask;
import com.ruoyi.live.tool.utils.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller("oldLiveExamTaskController")
@RequestMapping({"/exam"})
public class LiveExamTaskController extends BaseController {
    @Autowired
    LiveExamTaskService service;

    public LiveExamTaskController() {
    }

    @RequestMapping({"/LiveExamTaskController/index"})
    public String index() {
        return "exam/live_exam_task_list";
    }

    @ResponseBody
    @RequestMapping({"/LiveExamTaskController/setProduct"})
    @PreAuthorize("@ss.hasAnyRoles('admin')")
    public Message setProduct(String ids) {
        try {
            this.service.setProduct(ids);
            return new Message(true, "");
        } catch (Exception var3) {
            var3.printStackTrace();
            return new Message(false, "");
        }
    }

    @ResponseBody
    @RequestMapping({"/LiveExamTaskController/query"})
    public TableDataInfo query(LiveExamTask entity) {
        this.startPage();
        List<LiveExamTask> list = this.service.query(entity);
        return this.getDataTable(list);
    }

    @ResponseBody
    @RequestMapping({"/LiveExamTaskController/add"})
    @PreAuthorize("@ss.hasAnyRoles('teacher,admin')")
    public Message add(LiveExamTask entity) {
        try {
            this.service.addLiveExamTask(entity);
            return new Message(true, "新增成功");
        } catch (Exception var3) {
            var3.printStackTrace();
            return new Message(false, var3.getMessage());
        }
    }

    @ResponseBody
    @RequestMapping({"/LiveExamTaskController/update"})
    @PreAuthorize("@ss.hasAnyRoles('teacher,admin')")
    public Message update(LiveExamTask entity) {
        try {
            this.service.updateLiveExamTask(entity);
            return new Message(true, "修改成功");
        } catch (Exception var3) {
            var3.printStackTrace();
            return new Message(false, var3.getMessage());
        }
    }

    @ResponseBody
    @RequestMapping({"/LiveExamTaskController/delete"})
    @PreAuthorize("@ss.hasAnyRoles('teacher,admin')")
    public Message delete(String id) {
        try {
            this.service.deleteLiveExamTask(id.split(","));
            return new Message(true, "删除成功");
        } catch (Exception var3) {
            var3.printStackTrace();
            return new Message(false, var3.getMessage());
        }
    }

    @RequestMapping({"/LiveExamTaskController/view"})
    public ModelAndView view(Long id, String page) {
        ModelAndView mv = new ModelAndView("exam/" + page);
        if (id != null) {
            try {
                mv.addObject("entity", this.service.getLiveExamTask(id));
            } catch (Exception var5) {
                return (new ModelAndView("error")).addObject("tip", var5.getMessage());
            }
        }

        return mv;
    }
}
